package reference;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;

public class RecordError {
public static void WriteError(String uid, String description) throws IOException {
		
		File folder = new File(System.getProperty("user.dir")+File.separator+"local");
		if(folder.isDirectory()==false)
			folder.mkdir();
		File aRecord = new File(folder,"ErrorRecord.txt");
		if(aRecord.exists()!=true)  aRecord.createNewFile();

//				e1.printStackTrace();
		
		BufferedReader br = new BufferedReader(new FileReader(aRecord));
		List<String> content = new ArrayList<String>();
		String str = null;
		while((str = br.readLine())!=null){
			content.add(str);
		}
		br.close();
		
		BufferedWriter bw = new BufferedWriter(new FileWriter(aRecord));
		
		GregorianCalendar now = new GregorianCalendar();
		int mounth = now.get(Calendar.MONTH);
		int day = now.get(Calendar.DAY_OF_MONTH);
		int hour = now.get(Calendar.HOUR_OF_DAY);
		int min = now.get(Calendar.MINUTE);
		int sec = now.get(Calendar.SECOND);
		bw.write(mounth+"月"+day+"日"+hour+"时"+min+"分"+sec+"秒"+"\r\n");
		
		bw.write(uid+"\r\n");
		bw.write(description+"\r\n\r\n");
		
		for(String s : content){
			bw.write(s+"\r\n");
		}
		

		

		
		bw.close();
		
	}
}
